package org.cytoscape.myapp.cytoscape_app_v1.internal.model;

import java.util.List;
import java.util.Set;
import java.util.Vector;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.group.CyGroup;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.myapp.cytoscape_app_v1.internal.metrics.domain.TrustedRelationship;

public class StateExpanded extends StateCyGroups {

	private String name = "Expanded";
	
	public StateExpanded(CyApplicationManager applicationManager){
		super(applicationManager);
	}

	public void changeStateGroup(Set<CyGroup> groups) {
		for(CyGroup grupo:groups){
			grupo.collapse(applicationManager.getCurrentNetwork());
		}
	}
	
	public StateCyGroups getNextState() {
		return new StateCollapsed(applicationManager);
	}
	
	public List<CyNode> getNodes(){
		return applicationManager.getCurrentNetwork().getNodeList();
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public List<TrustedRelationship> getListTrustedRelationships() {	
		CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
		List<TrustedRelationship> listTr = new Vector<TrustedRelationship>();
		List<CyEdge> edges = cyNetwork.getEdgeList();
		
		for(CyEdge edge:edges){
	
			String[] usersIds = cyNetwork.getDefaultEdgeTable().getRow(edge.getSUID()).get("shared name", String.class).split(" ");
			
			try{
				Double confianza = cyNetwork.getDefaultEdgeTable().getRow(edge.getSUID()).get("ponderacion", Double.class);
				double num = 0;
				if (confianza != null)
					num = confianza;
				listTr.add(new TrustedRelationship(usersIds[0],usersIds[2],num));
			}
			catch (Exception e){
				e.getMessage();
			}
		}
		
		return listTr;
		
	}
}
